Skip to content

id: note policies survive a real host restart — persist + restore the checkpoint snapshot (#3819) - #12708

Merged
dezren39 merged 2 commits into
mainfrom
archer-lane-aw/3819-host-persistence
Nov 22, 2026
Merged

dezren39 merged 2 commits into
mainfrom
archer-lane-aw/3819-host-persistence

Conversation

@dezren39

@dezren39 dezren39 commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

Part of #3819 — slice 1 of the remainder named in the Lane AD record: host persistence wiring for the note-policy snapshot API landed in #12637.

The gap

The snapshot pair existed (NoteCheckpoints::policies() / seed_policies(), CollabState::note_policies() / seed_note_policies()) and the restart path was proven at the log/session layer — but no host called it across a real restart. web_routers_with_surface (the id serve path) built its CollabState memory-only, so a restarted server still reopened every scoped note as public. The events side also had no durable form: AppliedNote lacked the serde derives its fields already carry.

What lands

  • id-store: AppliedNote is now Serialize/Deserialize — the events are the durable form of the log, persistable alongside the policy records.
  • id-web: NoteCheckpointSnapshot (events + policies in one document — never written or read apart), CollabState::note_snapshot() / restore_note_snapshot() (events first, then policies, validated as a whole via from_events_with_policies), and a snapshot path installed by with_note_snapshot_path. Every mutation that leaves the log in a complete state — a publication, a policy change, a full restore — rewrites the file atomically (temp name + rename in the same directory). Persist is deliberately not hooked into the individual seed steps, so the file never holds an events-only intermediate that would reopen notes as public after a crash. A write failure is logged, not propagated: the mutation already landed in memory.
  • Serve wiring: web_routers_with_surface installs the snapshot path beside the identity store (.note-checkpoints.json next to .identity.redb) and restores before any router serves. Missing file = fresh host; a file that does not parse or does not fold fails startup — per the seed API's contract, a refused restore is a failed restart, never a silent reopen.

Oracle and evidence

Failing first (tests-only commit 14bf14a764a): compile fails with exactly the missing pieces — cannot find type NoteCheckpointSnapshot, no method named with_note_snapshot_path (5 errors).

The oracle is the host restart drill, test_note_policies_survive_a_host_restart_through_the_snapshot_file: a live state with a snapshot path persists as it mutates (file parses; 2 events, 2 policy records); a fresh state over the same file restores — granted user and group member chain onto the scoped note, a stranger is refused and the refusal records nothing, and a public note stays public for the same stranger. Plus test_a_corrupt_note_snapshot_fails_the_restart_not_opens_notes.

Verification (laptop, nix develop inside pkgs/id):

  • The two new tests: 2 passed.
  • cargo test -p id-store -p id-web --lib: id-store 244 passed / 0 failed (unchanged from baseline), id-web 737 passed / 0 failed (735 baseline + 2 new).
  • cargo fmt --check -p id-store -p id-web: clean. No clippy findings in the touched files (workspace -D warnings clippy debt in unrelated crates is the standing clippy-lint gate red since 2026-11-02: 571 deny-level sites in pkgs/id (campaign) #6462 campaign, untouched here).

Merge danger

Low-moderate. Behavior change is confined to the serve path: a host that has never checkpointed a note sees no file and no change. A host with a snapshot restores it at startup; a corrupt snapshot now fails startup loudly instead of serving notes reopened to public — that loudness is the point. No wire or storage format changes elsewhere; AppliedNote's new derives are additive.

Remainders on #3819, unchanged and in order: (2) replica sync of policies (needs the note.policy ordering-rule design note first), (3) wire-level tests.


Prove it works
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

Failing-first oracle for the host persistence wiring slice: a live
CollabState with a snapshot path persists its checkpoint log as it
mutates; a fresh state over the same file restores events and
policies, so a scoped note stays scoped (granted user and group
member chain on, stranger refused, refusal records nothing) and a
public note stays public. A corrupt snapshot must fail the restart,
never silently reopen notes.
The snapshot API from the previous slice had no caller across a
restart: the serving host built its CollabState memory-only, so a
rebuilt checkpoint log still reopened every scoped note as public
in the running server.

- id-store: AppliedNote is now Serialize/Deserialize — its fields
  already were — so the log's events have a durable form alongside
  the policy records.
- id-web: NoteCheckpointSnapshot (events + policies in one
  document) with CollabState::note_snapshot /
  restore_note_snapshot (events first, then policies, validated as
  a whole) and a snapshot path installed by
  with_note_snapshot_path. Every mutation that leaves the log in a
  complete state — a publication, a policy change, a full restore —
  rewrites the file atomically (temp name + rename); a write failure
  is logged, never misreported as a failed mutation.
  restore_persisted_note_snapshot treats a missing file as a fresh
  host and a corrupt or non-folding file as a failed restart.
- id-web serve path (web_routers_with_surface): the collab state
  gets the snapshot path beside the identity store
  (.note-checkpoints.json next to .identity.redb) and restores
  before any router serves; a bad snapshot fails startup.

Oracle: the host restart drill — a live state persists as it
mutates; a fresh state over the same file restores, and the
boundary holds (granted user and group member chain on, stranger
refused with nothing recorded) while a public note stays public.
Plus a corrupt-snapshot test: failed restart, not silent reopen.

Verification (laptop, pkgs/id dev shell): the two new tests pass;
cargo test -p id-store -p id-web --lib: 244 + 737 passed, 0 failed
(id-web 735 baseline + 2 new); cargo fmt --check clean; no clippy
findings in the touched files.
@dezren39
dezren39 requested a review from a team as a code owner November 22, 2026 23:15
@coderabbitai

coderabbitai Bot commented Nov 22, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 22 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: bf29a277-9cf8-4b4c-a617-c9173f692d1b
Commits

Reviewing files that changed from the base of the PR and between 7817b4e and 77e080e.

Files selected for processing: 3

  • pkgs/id/crates/id-store/src/notes.rs
  • pkgs/id/crates/id-web/src/collab.rs
  • pkgs/id/crates/id-web/src/lib.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-22T23:16:39.135456Z 77e080e PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant